package com.evany.cloud.evanyhyStrixDashboard.controller;

import com.evany.cloud.evanyhyStrixDashboard.service.TestFeignService;
import com.evany.cloud.evanyhyStrixDashboard.service.TestService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/hystrix-dashboard")
public class TestController {


    @Autowired
    TestService helloService;

    @GetMapping(value = "/hi")
    public String hi(@RequestParam String name) {
        return helloService.hiService( name );
    }

    @Autowired
    TestFeignService testFeignService;

    @GetMapping(value = "/hi2")
    public String sayHi(@RequestParam String name) {
        return testFeignService.sayHiFromClientOne( name );
    }

    @GetMapping(value = "/hi3")
    @HystrixCommand(fallbackMethod = "hi3Error")
    public String hi3(@RequestParam String name) {
        return helloService.hiService( name );
    }

    /**
     *  EnableHystrix ribbon
     *  此方法与主调用方法参数保持一致
     */
    public String hi3Error(String name) {
        return "hi hi3Error";
    }

    @GetMapping(value = "/hi4")
    public String hi4(@RequestParam String name) {
        return hi3Error(name);
    }
}
